package com.gch.programa.validator;

import com.gch.programa.managed.LoginBean;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author DanJoas
 */
@FacesValidator(value = "selectVacio")
public class SelectVacioValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

        LoginBean loginBean = (LoginBean) FacesContext.getCurrentInstance().
                getExternalContext().getSessionMap().get("loginBean");

        ResourceBundle rb = ResourceBundle.getBundle("com.gch.programa.i18n.global-messages",
                loginBean.getLocale());

        if (value == null || value.toString().equals("2")) {
            FacesMessage fm = new FacesMessage(rb.getString("gch_programa_error_vacio"));         
            throw new ValidatorException(fm);
        }
    }
}